import pandas as pd
from pyecharts.charts import *
from pyecharts import options as opts

df=pd.read_csv('../csv/tag_name.csv')
result=df.groupby('tag_name')['like_count'].sum()
result.to_csv('../csv/tag_like.csv')
like=pd.read_csv('../csv/tag_like.csv')
like_1= like.sort_values(by="like_count", ascending=False)
like_1.to_csv('../csv/tag_like_1.csv')

def make_bar_1():
    data=pd.read_csv("../csv/tag_like_1.csv")
    x_data = list(data['tag_name'])
    y_data = list(data['like_count'])
    # print(x_data)
    # print(y_data)
    bar=Bar()
    bar.add_xaxis(x_data)
    bar.add_yaxis('点赞数',y_data)
    bar.set_global_opts(
        xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=-15)),
        title_opts=opts.TitleOpts(title="标签对点赞数的影响"),
        datazoom_opts=[opts.DataZoomOpts(range_start=0, range_end=200, orient="horizontal")]
    )
    bar.render('../html/标签对点赞数的影响.html')
    return bar

if __name__ == "__main__":
    make_bar_1()